package com.lynn.springboot_demo.task;

import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * @author cl
 * @Date 2020/4/18 16:22
 * 异步任务
 */
@Component
public class AsyncTask {

    @Async
    public void test1() throws Throwable {
        long l = System.currentTimeMillis();
        Thread.sleep(10000);
        long l1 = System.currentTimeMillis();
        System.out.println("任务1耗时:" + (l1 - l) + "毫秒");
    }
//    @Async
    public void test2() throws Throwable {
        long l = System.currentTimeMillis();
        Thread.sleep(3000);
        long l1 = System.currentTimeMillis();
        System.out.println("任务2耗时:" + (l1 - l) + "毫秒");
    }
//    @Async
    public void test3() throws Throwable {
        long l = System.currentTimeMillis();
        Thread.sleep(5000);
        long l1 = System.currentTimeMillis();
        System.out.println("任务3耗时:" + (l1 - l) + "毫秒");
    }
}
